package com.ktjiaoyu.service.impl;

import com.ktjiaoyu.entity.Supplier;
import com.ktjiaoyu.entity.SysUser;
import com.ktjiaoyu.mapper.SupplierMapper;
import com.ktjiaoyu.service.SupplierService;
import com.ktjiaoyu.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/12/19  14:23
 */
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;

    /**
     * 分页
     * @param supplier
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public Page<Supplier> findPage(Supplier supplier, Integer pageNo, Integer pageSize) {
        Page<Supplier> page=new Page<>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        //查看总页数
        Integer count=supplierMapper.count(supplier);
        page.setTotalCount(count);
        Integer pageBegin=(pageNo-1)*pageSize;
        List<Supplier> list=supplierMapper.getPage(supplier, pageBegin, pageSize);
        page.setData(list);
        return page;
    }

    /**
     * 添加供货商信息
     * @param supplier
     * @return
     */
    @Override
    public boolean insert(Supplier supplier) {
        return supplierMapper.insert(supplier)>0;
    }

    @Override
    public boolean update(Supplier supplier) {
        return supplierMapper.update(supplier)>0;
    }

    @Override
    public Supplier findById(Long id) {
        return supplierMapper.getById(id);
    }

    @Override
    public List<Supplier> getAll() {
        return supplierMapper.getAll();
    }

    @Override
    public Supplier selectSupCode(String supCode) {
        return supplierMapper.selectSupCode(supCode);
    }

    @Override
    public boolean delete(Integer id) {
        return supplierMapper.delete(id)>0;
    }
}
